package com.juneng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageHelper;
import com.juneng.common.Condition;
import com.juneng.config.PageResult;
import com.juneng.entity.Course;
import com.juneng.utils.BeanCopyUtils;
import com.juneng.entity.CourseList;
import com.juneng.mapper.CourseListMapper;
import com.juneng.service.ICourseListService;
import com.juneng.dto.CourseListDto;
import com.juneng.dto.CourseListQueryDto;
import com.juneng.vo.CourseListVo;
import com.juneng.vo.CourseVo;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import lombok.AllArgsConstructor;

import java.util.List;

/**
 * 课程目录 服务实现类
 *
 * @author zds
 * @since 2021-07-08
 */
@Service
@AllArgsConstructor
public class CourseListServiceImpl implements ICourseListService {

    protected CourseListMapper courseListMapper;

    @Override
    public IPage<CourseListVo> page(CourseListQueryDto dto) {
//        List<CourseList> courseListsNum = courseListMapper.selectList(new QueryWrapper<>());
//        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
//        QueryWrapper<CourseList> objectQueryWrapper = new QueryWrapper<>();
//        if (dto.getListId() != null) {
//            objectQueryWrapper.eq("course_id", dto.getListId());
//        }
//        List<CourseList> courseLists = courseListMapper.selectList(objectQueryWrapper);
//
//        return new PageResult<>(dto.getPageNum(), dto.getPageSize(), courseLists, courseListsNum.size());
        IPage<CourseVo> page = Condition.getPage(dto);
        IPage<CourseListVo> page1 = courseListMapper.page(page, dto);
        return page1;
    }

    @Override
    public List<CourseList> list(CourseListQueryDto dto) {
        List<CourseList> courseListsNum = courseListMapper.selectList(new QueryWrapper<>());
        QueryWrapper<CourseList> objectQueryWrapper = new QueryWrapper<>();
        if (dto.getCourseId() != null) {
            objectQueryWrapper.eq("course_id", dto.getCourseId());
        }
        List<CourseList> courseLists = courseListMapper.selectList(objectQueryWrapper);
        return courseLists;
    }

    @Override
    public Integer save(CourseListDto dto) {
        return courseListMapper.insert(BeanCopyUtils.copy(dto, CourseList.class));
    }
     //
    @Override
    public Integer updateById(CourseListDto dto) {
        return courseListMapper.updateById(BeanCopyUtils.copy(dto, CourseList.class));
    }

    @Override
    public Integer deleteLogic(List<Integer> toIntList) {
        return courseListMapper.deleteBatchIds(toIntList);
    }

    @Override
    public CourseList getById(Integer id) {
        return courseListMapper.selectById(id);
    }
}
